#!/usr/bin/env python
# encoding: utf-8
"""
@file: dandiaoxing.py
@time: 2016/11/15 下午4:53
"""
from functools import reduce
# 三角函数的单调性和单调区间的问题
from mathsolver.functions.base import *
from sympy import sin, cos, tan, pi, ceiling, floor, EmptySet, Abs, expand, asin, acos, atan, cot, factor, solveset
from mathsolver.functions.sanjiao import sanjiao_utils as su
from mathsolver.functions.budengshi import common_opers as co
from mathsolver.functions.sanjiao.huajian import trig_simplify
from itertools import chain
from mathsolver.functions.sanjiao.zuizhi import _convert_trig_f
from mathsolver.functions.sanjiao.sanjiaobudengshi import JieSanJiaoBuDengShi
from sympy.sets.fancysets import Integers
from mathsolver.functions.sanjiao.sanjiao_constants import TrigIntervalSearch
from operator import add

TRIG_INCR_INTERVAL = {'sin': Interval(sympify('2*k*pi - pi/2'), sympify('2*k*pi + pi/2')),
                      'cos': Interval(sympify('2*k*pi - pi'), sympify('2*k*pi')),
                      'tan': Interval(sympify('k*pi - pi/2'), sympify('k*pi + pi/2'))}  # 三角函数的增区间
TRIG_DECR_INTERVAL = {'sin': Interval(sympify('2*k*pi + pi/2'), sympify('2*k*pi + 3/2*pi')),
                      'cos': Interval(sympify('2*k*pi'), sympify('2*k*pi + pi'))}  # 三角函数的减区间


# 最简单的三角函数单调性问题
class DanDiaoQuJian001(BaseFunction):
    def solver(self, *args):
        if len(args) > 2:
            raise Exception('try error')
        self.label.add('标准三角函数单调区间')
        y_symb, trig_f = args[0].sympify()
        text = args[1]
        simp_f = trig_simplify(trig_f)
        simp_f = _convert_trig_f(simp_f)
        self.steps.append(['化简得 %s' % args[0].printing(), ' '])
        self.steps.append(['= ' + new_latex(simp_f), ''])
        trig_mon, _ = co.split_mons_const(simp_f)
        coef = su.trig_coeff(trig_mon)  # 三角函数系数
        trig_arg = su.trig_arg(trig_mon)  # 三角函数参数
        trig_cl = su.trig_type(trig_mon)  # 三角函数的类型
        symb = list(trig_arg.free_symbols)[0]
        if coef > 0:  # 三角函数系数大于0
            if text.find('增') >= 0 or text.find('增') >= 0:
                intl = TRIG_INCR_INTERVAL[str(trig_cl)]
                intl_text = '递增'
            else:
                intl = TRIG_DECR_INTERVAL[str(trig_cl)]
                intl_text = '递减'
        else:
            if text.find('增') >= 0 or text.find('增') >= 0:
                intl = TRIG_DECR_INTERVAL[str(trig_cl)]
                intl_text = '递增'
            else:
                intl = TRIG_INCR_INTERVAL[str(trig_cl)]
                intl_text = '递减'
        self.steps.append(['由 %s <= %s <= %s' % (new_latex(intl.left), new_latex(trig_arg), new_latex(intl.right)), su.print_belong_z('k')])
        _, const = co.split_mons_const(trig_arg)
        symb_coef = trig_arg.coeff(symb)
        solve_left = (intl.left - const) / symb_coef
        solve_right = (intl.right - const) / symb_coef
        self.steps.append(['解得 %s < %s < %s' % (new_latex(solve_left), new_latex(solve_right), new_latex(symb)), ''])
        result_intl = Interval(solve_left, solve_right)
        self.steps.append(['\therefore 函数的%s区间为' % intl_text, new_latex(result_intl) + ' ' + su.print_belong_z('k')])
        self.output.append(BaseSymbolValue({symb: result_intl}))
        return self


# 给定区间的单调区间问题
# 函数y=sin(\\frac{1}{2}x+\\frac{π}{3}),x∈[-π,\\frac{π}{2}]的单调递增区间为().
class DanDiaoQuJian002(BaseFunction):
    def solver(self, *args):
        self.label.add('标准三角函数单调区间')
        y_symb, trig_f = args[0].sympify()
        symb_intl = args[1].interval
        text = args[2]
        self.steps.append(['化简得 %s' % args[0].printing(), ' '])
        simp_f = trig_simplify(trig_f)
        self.steps.append(['= ' + new_latex(simp_f), ''])
        trig_mon, _ = co.split_mons_const(simp_f)
        coef = su.trig_coeff(trig_mon)  # 三角函数系数
        trig_arg = su.trig_arg(trig_mon)  # 三角函数参数
        trig_cl = su.trig_type(trig_mon)  # 三角函数的类型
        symb = list(trig_arg.free_symbols)[0]
        if coef > 0:  # 三角函数系数大于0
            if text.find('递增') >= 0:
                intl = TRIG_INCR_INTERVAL[str(trig_cl)]
                intl_text = '递增'
            else:
                intl = TRIG_DECR_INTERVAL[str(trig_cl)]
                intl_text = '递减'
        else:
            if text.find('递增') >= 0:
                intl = TRIG_DECR_INTERVAL[str(trig_cl)]
                intl_text = '递增'
            else:
                intl = TRIG_INCR_INTERVAL[str(trig_cl)]
                intl_text = '递减'
        self.steps.append(['由 %s <= %s <= %s' % (new_latex(intl.left), new_latex(trig_arg), new_latex(intl.right)),
                           '' + su.print_belong_z('k')])
        _, const = co.split_mons_const(trig_arg)
        symb_coef = trig_arg.coeff(symb)
        solve_left = (intl.left - const) / symb_coef
        solve_right = (intl.right - const) / symb_coef
        self.steps.append(['解得 %s < %s < %s' % (new_latex(solve_left), new_latex(solve_right), new_latex(symb)), ' ' + su.print_belong_z('k')])
        self.steps.append(['\\because %s \\in %s' % (new_latex(symb), new_latex(symb_intl)), ''])
        left_k_value = list(solveset(solve_left - symb_intl.left))[0]
        left_k = ceiling(left_k_value)
        right_k_value = list(solveset(solve_right - symb_intl.right))[0]
        right_k = floor(right_k_value)
        left_k, right_k = (left_k, right_k) if left_k < right_k else (right_k, left_k)
        result_intl = EmptySet()
        ks = range(left_k, right_k + 1)
        for k in ks:
            tmp_intl = Interval.open(solve_left.subs('k', k), solve_right.subs('k', k))
            tmp_intl = tmp_intl.intersect(symb_intl)
            result_intl = result_intl.union(tmp_intl)
        self.steps.append(['\therefore 函数的%s区间为' % intl_text, new_latex(result_intl) + ' ' + su.print_belong_z('k')])
        self.steps.append(['故答案为：' + new_latex(result_intl), ' ' + su.print_belong_z('k')])
        self.output.append(co.to_base_interval(result_intl))
        return self


# 含绝对值的形如|A*sin(w*x+h)+b|的形式
# 函数y=|sinx|的一个单调增区间是()
# Input1 BaseEq
class DanDiaoQuJian004(BaseFunction):
    def solver(self, *args):
        self.label.add('绝对值三角函数单调区间')
        y_symbol, abs_expr = args[0].sympify()
        if type(abs_expr) != Abs:
            raise Exception('Type Match Error')
        trig_expr = abs_expr.args[0]
        x_symbol = sympify('x')
        k_symbol = sympify('k')
        _A, t_type, t_arg, _b = su.simp_trig_info(trig_expr)
        if _A < 0:
            trig_expr = -trig_expr
            self.steps.append(['由题意可知' + args[0].printing(), '=' + new_latex(Abs(trig_expr))])
        _A, t_type, t_arg, _b = su.simp_trig_info(trig_expr)
        text = args[1]
        t_arg = sympify(t_arg)
        _w = t_arg.coeff(x_symbol)
        _h = t_arg.subs(x_symbol, 0)
        _2kpi = 2 * k_symbol * pi
        _kpi = k_symbol * pi
        if t_type == sin:  # 正弦函数
            if _b - _A >= 0:
                inc_intl = Interval(expand(1 / _w * (2 * k_symbol * pi - pi / 2 - _h)),
                                    expand(1 / _w * (2 * k_symbol * pi + pi / 2 - _h)))

                dec_intl = Interval(expand(1 / _w * (2 * k_symbol * pi + pi / 2 - _h)),
                                    expand(1 / _w * (2 * k_symbol * pi + 3 * pi / 2 - _h)))
            elif _b + _A <= 0:
                dec_intl = Interval(expand(1 / _w * (2 * k_symbol * pi - pi / 2 - _h)),
                                    expand(1 / _w * (2 * k_symbol * pi + pi / 2 - _h)))

                inc_intl = Interval(expand(1 / _w * (2 * k_symbol * pi + pi / 2 - _h)),
                                    expand(1 / _w * (2 * k_symbol * pi + 3 * pi / 2 - _h)))
            elif -_A <= _b <= _A:
                inc_intl1 = Interval(expand(1 / _w * (2 * k_symbol * pi + asin(-_b / _A) - _h)),
                                     expand(1 / _w * (2 * k_symbol * pi + pi / 2 - _h)))
                inc_intl2 = Interval(expand(1 / _w * (2 * k_symbol * pi + pi - asin(-_b / _A) - _h)),
                                     expand(1 / _w * (2 * k_symbol * pi + 3 * pi / 2 - _h)))
                inc_intl = inc_intl1.union(inc_intl2)

                dec_intl1 = Interval(expand(1 / _w * (2 * k_symbol * pi - pi / 2 - _h)),
                                     expand(1 / _w * (2 * k_symbol * pi + asin(-_b / _A) - _h)))
                dec_intl2 = Interval(expand(1 / _w * (2 * k_symbol * pi + pi / 2 - _h)),
                                     expand(1 / _w * (2 * k_symbol * pi + pi - asin(-_b / _A) - _h)))
                dec_intl = dec_intl1.union(dec_intl2)
        elif t_type == cos:  # 余弦函数
            if _b - _A >= 0:
                inc_intl = Interval(expand(1 / _w * (_2kpi - pi - _h)), 1 / _w * expand(_2kpi - _h))
                dec_intl = Interval(expand(1 / _w * (_2kpi - _h)), 1 / _w * expand(_2kpi + pi - _h))
            elif _b + _A <= 0:
                inc_intl = Interval(expand(1 / _w * (_2kpi - _h)), expand(1 / _w * (_2kpi + pi - _h)))
                dec_intl = Interval(expand(1 / _w * (_2kpi - pi - _h)), expand(1 / _w * (_2kpi - _h)))
            elif -_A <= _b <= _A:
                inc_intl1 = Interval(expand(1 / _w * (_2kpi + acos(-_b / _A) - _h)),
                                     expand(1 / _w * (_2kpi + - _h)))
                inc_intl2 = Interval(expand(1 / _w * (_2kpi - acos(-_b / _A) - _h)),
                                     expand(1 / _w * (_2kpi + pi - _h)))
                inc_intl = inc_intl1.union(inc_intl2)
                dec_intl1 = Interval(expand(1 / _w * (_2kpi - pi - _h)),
                                     expand(1 / _w * (_2kpi + acos(-_b / _A) - _h)))
                dec_intl2 = Interval(expand(1 / _w * (_2kpi - _h)),
                                     expand(1 / _w * (_2kpi - acos(-_b / _A) - _h)))
                dec_intl = dec_intl1.union(dec_intl2)
        elif t_type == tan:
            inc_intl = Interval(expand(1 / _w * (_kpi + atan(-_b / _A) - _h)), expand(1 / _w * (_kpi + pi / 2 - _h)))
            dec_intl = Interval(expand(1 / _w * (_kpi + pi / 2 - _h)),
                                expand(1 / _w * (_kpi + pi / 2 + atan(-_b / _A) - _h)))
        _Z = Integers()
        if text.find('增') >= 0:
            self.steps.append(['求得单增区间为' + new_latex(inc_intl), '其中k \\in ' + new_latex(_Z)])
            self.output.append(BaseSymbolValue({TrigIntervalSearch.INC_INTL: inc_intl}))
        elif text.find('减') >= 0:
            self.steps.append(['求得单减区间为' + new_latex(dec_intl), '其中k \\in ' + new_latex(_Z)])
            self.output.append(BaseSymbolValue({TrigIntervalSearch.DEC_INTL: dec_intl}))
        return self


# 元函数36:含有平方的 复合三角函数
# 函数f(x)=cos^{2}x-2cos^{2}\\frac{x}{2}的一个单调增区间是()
class DanDiaoQuJian005(BaseFunction):
    def solver(self, *args):
        self.label.add('复合三角函数单调区间')
        y_symbol, trig_expr = args[0].sympify()
        f2 = _convert_trig_f(str(trig_expr))
        self.steps.append(['函数' + new_latex(y_symbol) + '=' + new_latex(trig_expr) + '=' + new_latex(f2), ''])
        sec_triangle_mons1 = co.find_reg_expr(r'sin\(.*?\)\*\*2', f2)
        sec_triangle_mons2 = co.find_reg_expr(r'cos\(.*?\)\*\*2', f2)
        sec_mons = chain(sec_triangle_mons1, sec_triangle_mons2)
        if not sec_mons:
            raise Exception('Type Match Error')
        _x = sympify('x')
        sec_mon = list(sec_mons)[0]
        sec_mon = re.search(r'(sin|cos)\(.*\)', str(sec_mon)).group()
        _1, t_type, t_arg, _2 = su.simp_trig_info(sec_mon)
        t_symbol = sympify('t')
        t_sub = t_type(t_arg)
        f3 = f2.subs(t_sub, t_symbol)
        self.steps.append(['原函数看作g(t)=' + new_latex(f3), ""])
        t_sub_f3, t_sub_f3_point = co.top_point_expr(f3, t_symbol)
        self.steps.append([r'\therefore ' + new_latex(sympify('g(x)')) + '=' + new_latex(t_sub_f3), ''])
        t_sub_f2_coef = t_sub_f3.coeff((t_symbol - t_sub_f3_point[0]) ** 2)

        if t_sub_f2_coef > 0:  # 顶点式系数大于0
            dec_intl = Interval(-1, 1).intersect(Interval(-S.Infinity, t_sub_f3_point[0]))  # 单调递增区间
            arg_x_dec_intl = list(JieSanJiaoBuDengShi().solver(BaseIneqs(co.interval_2_ineq_list(dec_intl, t_type(t_arg)))).output[0].sympify().values())[0]  # 对应的x的单调递减区间
            inc_intl = Interval(-1, 1).intersect(Interval(t_sub_f3_point[0], S.Infinity))  # 低调递减区间
            arg_x_inc_intl = list(JieSanJiaoBuDengShi().solver(BaseIneqs(co.interval_2_ineq_list(inc_intl, t_type(t_arg)))).output[0].sympify().values())[0]  # 对应的x的单调递增区间
        else:
            inc_intl = Interval(-1, 1).intersect(Interval(-S.Infinity, t_sub_f3_point[0]))
            arg_x_inc_intl = list(JieSanJiaoBuDengShi().solver(BaseIneqs(co.interval_2_ineq_list(inc_intl, t_type(t_arg)))).output[0].sympify().values())[0]  # 对应的x的单调递增区间
            dec_intl = Interval(-1, 1).intersect(Interval(t_sub_f3_point[0], S.Infinity))
            arg_x_dec_intl = list(JieSanJiaoBuDengShi().solver(BaseIneqs(co.interval_2_ineq_list(dec_intl, t_type(t_arg)))).output[0].sympify().values())[0]  # 对应的x的单调递减区间
        self.steps.append(['r\therefore ' + new_latex(sympify('g(t)')) + '在' + new_latex(dec_intl) + '单调递减;',
                           '在' + new_latex(inc_intl) + '单调递增'])
        trig_inc_intl = list(DanDiaoQuJian001().solver(BaseEq(['y', t_type(t_arg)]), '单增').output[0].sympify().values())[0]
        trig_dec_intl = list(DanDiaoQuJian001().solver(BaseEq(['y', t_type(t_arg)]), '单减').output[0].sympify().values())[0]
        # 合并区间
        last_inc_intl1 = su.param_intl_intersect(arg_x_inc_intl, trig_inc_intl)
        last_inc_intl2 = su.param_intl_intersect(arg_x_dec_intl, trig_dec_intl)
        last_inc_intl = last_inc_intl1.union(last_inc_intl2)
        last_dec_intl1 = su.param_intl_intersect(arg_x_inc_intl, trig_dec_intl)
        last_dec_intl2 = su.param_intl_intersect(arg_x_dec_intl, trig_inc_intl)
        last_dec_intl = last_dec_intl1.union(last_dec_intl2)
        text = args[1]
        if text.find('增') >= 0:  # 原函数的递增    对应t的递减 cos的递减；或者 t的递增 cos的递增。
            self.output.append(BaseSymbolValue({_x: last_inc_intl}))
            if isinstance(last_inc_intl, Union):
                self.steps.append(['所以当x \\in ' + new_latex(last_inc_intl1),
                                   '或者' + new_latex(last_inc_intl2) + '时原函数单调递增 ' + su.print_belong_z('k')])
            else:
                self.steps.append(['所以当x \\in ' + new_latex(last_inc_intl), '时原函数单调递增 ' + su.print_belong_z('k')])
        elif text.find('减') >= 0:
            self.output.append(BaseSymbolValue({_x: last_dec_intl}))
            if isinstance(last_dec_intl, Union):
                self.steps.append(['所以当x \\in ' + new_latex(last_dec_intl1),
                                   '或者' + new_latex(last_dec_intl2) + '时原函数单调递减 ' + su.print_belong_z('k')])
            else:
                self.steps.append(['所以当x \\in ' + new_latex(last_dec_intl), '时原函数单调递减 ' + su.print_belong_z('k')])
        return self


class SanJiaoDanDiaoQuJian(BaseFunction):
    CLS = [DanDiaoQuJian001, DanDiaoQuJian005, DanDiaoQuJian002, DanDiaoQuJian004]

    def solver(self, *args):
        tmp_args = [arg for arg in args]
        for index, arg in enumerate(tmp_args):
            if isinstance(arg, BaseSinFunc):
                tmp_args[index] = BaseEq([arg.name, arg.expression])
        r = None
        for cl in SanJiaoDanDiaoQuJian.CLS:
            try:
                r = cl(verbose=True).solver(*tmp_args)
                r.label.add('三角函数单调区间')
                break
            except Exception:
                pass
        if not r:
            raise Exception('Can not solve the question')
        return r


# Input paramer1 函数; paramer2 区间; paramer3 单调性
class SanJiaoHanShuDanDiaoXinQiuCan001(BaseFunction):
    def solver(self, *args):
        self.label.add('三角函数区间单调性求参数')
        y_symbol, f_expr = args[0].sympify()
        src_expr = f_expr
        f_expr = su.i_trig_simplify(f_expr)
        if src_expr != f_expr:
            self.steps.append(['由题意可知' + args[0].printing(), '=' + new_latex(f_expr)])
        intl = args[1].interval
        _l, _r = intl.left, intl.right
        _l_open, _r_open = intl.left_open, intl.right_open
        text = args[2]
        t_coef, t_type, t_arg, _b = su.simp_trig_info(f_expr)
        t_arg = sympify(t_arg)
        _kw = t_arg.subs('x', 1)
        t_arg_const = t_arg.subs('x', 0)
        ineqs = []
        if t_type == sin and t_coef > 0 and t_arg_const == 0 and _l * _r <= 0:
            if text.find('增') >= 0:
                ineqs.append([_kw, '>', 0])
                ineqs.append([_kw * _r, '<=', pi / 2])
                ineqs.append([_kw * _l, '>=', -pi / 2])
            elif text.find('减') >= 0:
                ineqs.append([_kw, '<', 0])
                ineqs.append([_kw * _r, '>=', -pi / 2])
                ineqs.append([_kw * _l, '<=', pi / 2])
        elif t_type == cos and t_coef > 0 and t_arg_const == 0:
            if _l == 0 and _r > 0:
                if text.find('减') >= 0:
                    ineqs.append([_kw, '>', 0])
                    ineqs.append([_kw * _r, '<=', pi])
                elif text.find('增') >= 0:
                    ineqs.append([_kw, '<', 0])
                    ineqs.append([_kw * _r, '>=', -pi])
            elif _r == 0 and _l <= 0:
                if text.find('减') >= 0:
                    ineqs.append([_kw, '<', 0])
                    ineqs.append([_kw * _l, '<=', pi])
                elif text.find('增') >= 0:
                    ineqs.append([_kw, '<', 0])
                    ineqs.append([_kw * _l, '>=', -pi])
        elif t_type == tan and t_coef > 0 and t_arg_const == 0 and _l * _r <= 0:
            if text.find('增') >= 0:
                ineqs.append([_kw, '>', 0])
                ineqs.append([_kw * _r, '<=' if _r_open else '<=', pi / 2])
                ineqs.append([_kw * _l, '>=' if _l_open else '<', -pi / 2])
            elif text.find('减') >= 0:
                ineqs.append([_kw, '<', 0])
                ineqs.append([_kw * _r, '>=' if _r_open else '>', -pi / 2])
                ineqs.append([_kw * _l, '<=' if _l_open else '<', pi / 2])
        if not ineqs:
            raise Exception('Type Match Error')
        op_text = '单调递增' if text.find('增') >= 0 else '单调递减'
        self.steps.append(['因为' + args[0].printing(), '在' + new_latex(intl) + op_text])
        self.steps.append(['所以', BaseIneqs(ineqs).printing()])
        self.output.append(BaseIneqs(ineqs))
        return self


# 三角函数在给定区间上的单调性求参
# Input paramer1: 三角函数; paramer2:区间; paramer3:单调性
class SanJiaoHanShuDanDiaoXinQiuCan002(BaseFunction):
    @staticmethod
    def _param_factor(arg, _x, param):
        terms = map(lambda _: _[0] * _[1], arg.as_coefficients_dict().items())
        param_terms = filter(lambda _: _.has(param), terms)
        param_expr = reduce(add, param_terms)
        _x_coef = param_expr.coeff(_x)
        param_expr_factor = expand(param_expr / _x_coef)
        cosnt_terms = filter(lambda _: not _.has(param), terms)
        const = reduce(add, cosnt_terms) if cosnt_terms else 0
        return _x_coef, param_expr_factor, const

    def solver(self, *args):
        self.label.add('三角函数在给定区间上的单调性求参')
        arg1, arg2, arg3 = args
        arg1 = list(co.flatten(arg1.sympify()))
        if len(arg1) == 1:
            f_expr = arg1[0]
        elif len(arg1) == 2:
            f_expr = arg1[1]
        else:
            raise Exception('Illegal parameter')
        intl = arg2.interval
        left = intl.left
        right = intl.right
        _x = sympify('x')
        _k = sympify('k')
        param = list(f_expr.free_symbols - {_x})[0]
        t_coef, t_type, t_arg, t_const = su.simp_trig_info(f_expr)
        text = arg3
        if t_type in [sin, cos]:
            t_coef, t_type, t_arg, t_const = su.cos_2_sin(f_expr)
            mw, f2, _h = SanJiaoHanShuDanDiaoXinQiuCan002._param_factor(t_arg, _x, param)
            _t = f2.subs(_x, 0)
            ineqs = []
            if text.find('增') >= 0:
                ineqs.append([(2 * _k * pi - pi / 2 - _h) / mw - _t, '<=', left])
                ineqs.append([right, '<=', (2 * _k * pi + pi / 2 - _h) / mw - _t])
            elif text.find('减') >= 0:
                ineqs.append([(2 * _k * pi + pi / 2 - _h) / mw - _t, '<=', left])
                ineqs.append([right, '<=', (2 * _k * pi + 3 * pi / 2 - _h) / mw - _t])
            else:
                raise Exception('Can not solve the question')
        elif t_type in [tan, cot]:
            t_coef, t_type, t_arg, t_const = su.cot_2_tan(f_expr)
            f2 = factor(t_arg)
            _h = t_arg - f2
            mw = f2.subs(param, 1)
            term2 = f2 / mw
            _t = term2.subs(_x, 0)
            ineqs = []
            if text.find('减') >= 0:
                ineqs.append([(2 * _k * pi - pi / 2 - _h) / mw - _t, '<', left])
                ineqs.append([right, '<', (2 * _k * pi + pi - _h) / mw - _t])
        else:
            raise Exception('Illegal parameter')
        self.steps.append(['由题意可知', BaseIneqs(ineqs).printing() + '其中' + su.print_belong_z('k')])
        self.output.append(BaseIneqs(ineqs))
        self.output.append(BaseSymbolValue({_k: S.Integers}))
        return self


# 35.三角函数的单调性求参数
# Input paramer1 函数; paramer2 区间; paramer3 单调性
class SanJiaoHanShuDanDiaoXinQiuCan(BaseFunction):
    CLS = [SanJiaoHanShuDanDiaoXinQiuCan001, SanJiaoHanShuDanDiaoXinQiuCan002]

    def solver(self, *args):
        solve_result = None
        for cl in SanJiaoHanShuDanDiaoXinQiuCan.CLS:
            try:
                solve_result = cl(verbose=True)
                solve_result.known = self.known
                solve_result = solve_result.solver(*args)
                solve_result.label.add('三角函数单调性求参')
                break
            except Exception:
                solve_result = None
        if not solve_result:
            raise Exception('Can not solve the question')
        return solve_result


if __name__ == '__main__':
    pass
